package com.ats.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.ats.dao.FunctionDao_xh;
import com.ats.util.JDBCUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
 * 不同角色加载不同功能的DAO层实现类
 * @author xh
 *
 */
public class FunctionDaoImpl_xh implements FunctionDao_xh{

	public JSONArray getFincByPid(int pid, String fids) {
		// TODO Auto-generated method stub
		JSONArray   as = new JSONArray();
		StringBuffer  sql = new StringBuffer();
		sql.append(" select fid,fname,fstate,furl  from ats_function ");
		sql.append(" where parentId = ? ");
		sql.append(" and ");
		sql.append(" fid  in (");
		sql.append( fids );
		sql.append(" )");
		Connection  con = JDBCUtil.getConnection();
		PreparedStatement pst = null;
		try {
			pst = con.prepareStatement(sql.toString());
			pst.setInt(1, pid);
			ResultSet  rs = pst.executeQuery();
			while(rs.next()){
				JSONObject j = new JSONObject();
				j.put("id", rs.getInt("fid"));
				j.put("text",rs.getString("fname"));
				j.put("state",rs.getString("fstate"));
				JSONObject  attr = new JSONObject();
				attr.put("url", rs.getString("furl"));
				j.put("attributes", attr);
				as.add(j);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return as;
	}

}
